package lab.domain;

import java.io.Serializable;
import java.util.HashSet;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Track extends NamedRecord<Track> implements Serializable, Cloneable {

    private long length;
    private int year;
    private SoundRecordingStudio soundRecordingStudio;
    private ChangableHashSet<Artist> artists;
    private ChangableHashSet<Genre> genres;

    public Track() {
        genres = new ChangableHashSet<Genre>();
        genres.setRecord(this);
        artists = new ChangableHashSet<Artist>();
        artists.setRecord(this);
    }
    
    public HashSet<Artist> getArtists() {
        return artists;
    }

    public void setArtists(ChangableHashSet<Artist> artists) {
        this.artists = artists;
        notifyChanged();
    }

    public HashSet<Genre> getGenres() {
        return genres;
    }

    public void setGenres(ChangableHashSet<Genre> genres) {
        this.genres = genres;
        notifyChanged();
    }

    public long getLength() {
        return length;
    }

    public void setLength(long length) {
        this.length = length;
        notifyChanged();
    }
    
    public void setLength(long length, boolean silent) {
        this.length = length;
        notifyChanged();
    }

    public SoundRecordingStudio getSoundRecordingStudio() {
        return soundRecordingStudio;
    }

    public void setSoundRecordingStudio(SoundRecordingStudio soundRecordingStudio) {
        this.soundRecordingStudio = soundRecordingStudio;
        notifyChanged();
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
        notifyChanged();
    }

    @Override
    public Track clone() {
        Track track = (Track) super.clone();
        track.artists = ((ChangableHashSet<Artist>)artists.clone());
        track.artists.setRecord(track);
        track.genres = ((ChangableHashSet<Genre>)genres.clone());
        track.genres.setRecord(track);
        
        if (soundRecordingStudio != null) {
            track.soundRecordingStudio = ((SoundRecordingStudio)soundRecordingStudio.clone());
        }
        
        return track;
    }

    @Override
    public void copy(Track object) {
        super.copy(object);
        this.artists = object.artists;
        this.artists.setRecord(this);
        this.genres = object.genres;
        this.genres.setRecord(this);
        this.soundRecordingStudio = object.soundRecordingStudio;
    }
    
}
